const arr = [1 << 10];
const arr2 = ["KB", "MB", "GB"]
for (let i = 1; i <= 2; i++) {
    arr[i] = arr[i - 1] << 10;
}
arr.reverse();
arr2.reverse();

/**
 * 将byte大小转为kb,mb,gb
 * @param num 
 * @returns 
 */
const getByteSize = (num:number) => {
    if (num < 1024) {
        return num + "字节";
    }
    for (const i in arr) {
        const r = num / arr[i];
        if (r > 1) {
            return r + arr2[i];
        }
    }
}

export {getByteSize};